package com.umedcn;

import com.umedcn.dao.TokenDao;
import com.umedcn.model.Token;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by jiangadam on 2017/7/27.
 */
@SpringBootApplication(scanBasePackages = {"dao", "mapper", "service"})
public class FilterUrlInterceptor implements HandlerInterceptor {

    @Resource
    private TokenDao tokenDao;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object o) throws Exception {

        // 在这里判断token，验证请求的合法性
         Token token = tokenDao.getToken("123");

         System.out.println("preHandle" + token);

        return true;
    }

    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("postHandle");
    }

    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("afterCompletion");
    }
}
